/*
 * Game - The main gameplay class
 *
 * Copyright 2008 James W. Hofmann
 *
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

package rules;

import lib3f.LCG;

class Game
{

	public var lcg : LCG;
	public var m : GameMap;
	public var fortdatas : IncHash<FortressData>;
	public var creeps : IncHash<Creep>;
	public var shots : IncHash<Shot>;

	public var seed : Int;

	public var creepspawnshorepaths : Array<CreepPath>;
	public var creepshorebasepath : CreepPath;

	public var shorelineinner : Array<lib3f.IntPoint>;
	public var shorelineouter : Array<lib3f.IntPoint>;

	public var wavehash : IntHash<Wave>;
	public var wavenum : Int;
	public var wavecornercycle : Int;
	public var timetonextwave : Int;
	inline public static var timebetweenwaves = 30*15;

	public var framessurvived : Int;

	public var energy : Int;
	public var numlinesplaced : Int;
	public var gameover : Bool;
	public var selectedtower : Shooter;
	
	public function new(?seed : Int)
	{
		framessurvived = 0;

		lcg = new LCG(seed);
		this.seed = lcg.seed;
		
		fortdatas = new IncHash();
		creeps = new IncHash();
		shots = new IncHash();

		energy = 10000;
		numlinesplaced = 0;
		timetonextwave = timebetweenwaves;

		gameover = false;
		
		RulesAPI.g = this; // otherwise stuff done in the constructor
						   // may fail
		
		m = new GameMap();
		
		this.m.genmap(0);

		this.m.addbase(
			this.m.tiles[GameMap.mapxcenter][GameMap.mapycenter]);
			
		creepspawnshorepaths = new Array();
		for (n in GameMap.corners)
		{
			creepspawnshorepaths.push(
				new CreepPath(CreepPath.path_spawntoshore,n[0],n[1]));
		}

		creepshorebasepath = new CreepPath(CreepPath.path_shoretobase,
							GameMap.mapxcenter, GameMap.mapycenter);

		shorelineinner = m.calcshoreinner();		
		shorelineouter = m.calcshoreouter();

		wavecornercycle = 0;
		wavenum = 0;
		wavehash = new IntHash();

		Wave.nextwave();
				
	}
			
}
